package reserve.utility;

import java.io.*;
import java.sql.*;
import java.util.Properties;

public class ConnectDB
{	
	private Properties dbProperties;
	private String jdbc;
	private String url;
	private String user;
	private String password;
	private String query;
	private Connection con;
	private Statement stmt;
	private ResultSet rset;

	private void init() throws IOException {
		dbProperties = new Properties();
		try {
			File filePath = new File("D:/rara/project/KIA/src/dbconnect.properties");
			FileInputStream fis = new FileInputStream(filePath);
			dbProperties.load(fis);
		} catch(IOException e) {
			System.out.println("-- IO Error!!! Properties : " + e);
		}
		this.jdbc = dbProperties.getProperty("driver");
		this.url = dbProperties.getProperty("url");
		this.user = dbProperties.getProperty("username");
		this.password = dbProperties.getProperty("password");
	}

	public ConnectDB() throws IOException {
		init();
		try	{
			Class.forName(jdbc);			
		} catch (ClassNotFoundException e) {
			System.out.println("-- JDBC Error!!! Class Not Found : " + e);
		}
	}

	public Connection openCon() {
		try	{
			con = DriverManager.getConnection(url, user, password);
//			System.out.println("-- Administrator Connection Open Success!");
		} catch (SQLException e)	{
			System.out.println("DB Error!!! : " + e);
		}
		return con;
	}

	public void closeCon(Connection con) {
		try {
			this.con = con;
			con.close();
//			System.out.println("-- Administrator Connection Close Success!");
		} catch (SQLException e) {
			System.out.println("DB Close Error : " + e);
		}
	}

	public void setQuery(String query) {
		this.query = query;
	}
/**
	public void setStmt() {
		try	{
			stmt.executeUpdate(query);			
		}
		catch (SQLException e) {
		}
	}
	public void setRset() {
		try	{
			rset = stmt.executeQuery(query);			
		}
		catch (SQLException e) {
		}
	}
	public Statement getStmt() {
		return stmt;
	}
	public ResultSet getRset() {
		return rset;
	}
**/
}